let loginModule = (function () {
    let $userName = $('.userName')
    let $userPass = $('.userPass')
    let $submit = $('.submit')

    function handle() {
        $submit.click(async function () {
            let name = $userName.val().trim()
            let password = $userPass.val().trim()
            //非空格式校验
            if (name === '') {
                alert('账号不能为空，请输入！');
                return;
            }
            if (password === '') {
                alert('密码不能为空，请输入！');
                return;
            }
            //md5加密
            password = md5(password)
            //请求发送
            let result = await axios.post('/user/login', {
                account: name,
                password
            })

            if (parseInt(result.code) === 0) {
                window.location.href = 'index.html';
            } else {
                console.log(result)
                alert('输入的账号密码有误，请重新输入！')
            }

        })
    }


    return {
        init() {
            handle();
        }
    }
})();
loginModule.init();